package com.gavin.lingxi.rtclib;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public abstract class AbsRTCMsgClient implements IRTCMsgClient{

    protected List<RTCMsgArrivedListener> listeners = Collections.synchronizedList(new ArrayList<>());

    @Override
    public void addRTCMsgArrivedListener(RTCMsgArrivedListener listener) {
        synchronized (listeners){
            if(listeners != null){
                listeners.add(listener);
            }
        }
    }

    @Override
    public void removeRTCMsgArrivedListener(RTCMsgArrivedListener listener) {
        synchronized (listeners){
            if(listeners != null){
                listeners.remove(listener);
            }
        }
    }

    @Override
    public void release() {
        synchronized (listeners){
            if(listeners != null){
                listeners.clear();
            }
        }
    }
}
